<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>详情</title>
    <link rel="stylesheet" type="text/css" href="../../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/aui.css" />
    <style>
        body {}
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <div class="aui-pull-left aui-btn" tapmode="tap-active" onclick="api.closeWin(this)">
            <span class="aui-iconfont aui-icon-left"></span>
        </div>
        <div class="aui-title">详情</div>
    </header>
    <ul class="aui-list aui-form-list">
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    所属项目：
                </div>
                <div class="aui-list-item-input">
                    <input readonly type="text" class="projName" placeholder="材料名称">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    材料名称：
                </div>
                <div class="aui-list-item-input">
                    <input readonly type="text" class="marName" placeholder="材料名称">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    材料供应商：
                </div>
                <div class="aui-list-item-input">
                    <input readonly type="text" class="marServer" placeholder="材料供应商">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    使用部位：
                </div>
                <div class="aui-list-item-input">
                    <input readonly type="text" class="part" placeholder="使用部位">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    监理：
                </div>
                <div class="aui-list-item-input">
                    <input readonly type="text" class="jianli" placeholder="监理人">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    抄送人：
                </div>
                <div class="aui-list-item-input">
                    <input readonly type="text" class="chaosong" placeholder="抄送人">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    建设单位验收：
                </div>
                <div class="aui-list-item-input">
                    <input readonly type="text" class="jies aui-padded-l-10 aui-text-info" placeholder="建设单位验收">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    备注：
                </div>
                <div class="aui-list-item-input">
                    <textarea readonly class="remark" placeholder="Textarea"></textarea>
                </div>
            </div>
        </li>
    </ul>
</body>
<script type="text/javascript" src="../../../script/api.js"></script>
<script type="text/javascript">
    var token = $api.getStorage('token');
    var uid = $api.getStorage('uid');
    var projData = [],
        jianliData = [],
        chaosongdata = [];
    apiready = function() {
        $api.fixStatusBar($api.dom('header'));
        // 初始化项目
        initdata();
        // 监理方
        initmember();
        // 抄送人
        initmember2();
        // 详情数据
        // console.log(JSON.stringify(api.pageParam));
        var itemId = api.pageParam.id;
        detaildata(itemId);
    };
    // 初始化项目数据
    function initdata() {
        api.ajax({
            url: $api.SERVE_URL + 'index.php/index/speed/projectList',
            method: 'post',
            headers: {
                "token": token
            },
            data: {
                values: {
                    'token_uid': uid
                }
            }
        }, function(ret, err) {
            if (ret) {
                var code = ret.code
                if (code === 200) {
                    projData = ret.data.list;
                }
            }
        });

    }

    function initmember() {
        api.ajax({
            url: $api.SERVE_URL + 'index.php/index/index/memberList',
            method: 'post',
            headers: {
                "token": token
            },
            data: {
                values: {
                    'group': false,
                    'types': 3,
                    'token_uid': uid
                }
            }
        }, function(ret, err) {
            if (ret) {
                var code = ret.code;
                if (code === 200) {
                    jianliData = ret.data.list;
                }
            }
        });
    }

    function initmember2() {
        api.ajax({
            url: $api.SERVE_URL + 'index.php/index/index/memberList',
            method: 'post',
            headers: {
                "token": token
            },
            data: {
                values: {
                    'group': false,
                    'token_uid': uid
                }
            }
        }, function(ret, err) {
            if (ret) {
                var code = ret.code;
                if (code === 200) {
                    chaosongdata = ret.data.list;
                }
            }
        });
    }

    function detaildata(id) {
        api.ajax({
            url: $api.SERVE_URL + 'index.php/index/Material/materialDetail',
            method: 'post',
            headers: {
                "token": token
            },
            data: {
                values: {
                    'id': id,
                    'token_uid': uid
                }
            }
        }, function(ret, err) {
            if (ret) {
                var code = ret.code;
                var data = ret.data
                if (code === 200) {
                    $api.val($api.dom('.marName'), data.material_name);
                    $api.val($api.dom('.marServer'), data.material_server);
                    $api.val($api.dom('.part'), data.position);
                    $api.val($api.dom('.remark'), data.remark);
                    // jianliData
                    for (var i = 0; i < projData.length; i++) {
                        if (projData[i].id === data.pid) {
                            $api.val($api.dom('.projName'), projData[i].project_name);
                        }
                    }
                    var jlstr = '', chaos = '';
                    for(var j = 0;j < jianliData.length; j++) {
                      if (data.jianli_accept.indexOf(jianliData[j].uid + '') !== -1) {
                        !jlstr ? (jlstr += jianliData[j].user_name) : jlstr += (',' + jianliData[j].user_name);
                      }
                    }
                    $api.val($api.dom('.jianli'), jlstr);
                    if (data.group) {
                      $api.val($api.dom('.chaosong'), chaosongdata.read_people);
                    } else {
                      for(var j = 0;j < chaosongdata.length; j++) {
                        if (data.read_people.indexOf(chaosongdata[j].uid + '') !== -1) {
                          !chaos ? (chaos += chaosongdata[j].user_name) : chaos += (',' + chaosongdata[j].user_name);
                        }
                      }
                      $api.val($api.dom('.chaosong'), chaos);
                    }
                    $api.val($api.dom('.jies'), data.isbuild ? "是" : "否");
                }
            }
        });
    }
</script>

</html>
